#define _CRT_SECURE_NO_WARNINGS 1

#include <algorithm>
#include <iostream>
#include<vector>
using namespace std;
int Fib(int x)
{
	if (x <= 0)
		return 0;
	if (x == 1)
		return 1;
	return Fib(x - 2) + Fib(x - 1);
}
int main() {
	int n;
	cin >> n;
	vector<int> v;
	int fb1 = 0;
	int fb2 = 1;
	int fb3;
	int num = n;
	while (num--) {
		fb3 = fb1 + fb2;
		fb1 = fb2;
		fb2 = fb3;
		v.push_back(fb3);
	}
	v.push_back(n);
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		if (v[i] == n)
		{
			if (v[i] - v[i - 1] > v[i] || v[i + 1] - v[i] > v[i])
			{
				cout << v[i];
				return 0;
			}
			if (v[i] - v[i - 1] > v[i + 1] - v[i])
			{
				int ret = v[i + 1] - v[i];
				cout << ret;
			}
			else if (v[i] - v[i - 1] < v[i + 1] - v[i]) {
				int ret = v[i] - v[i - 1];
				cout << ret;
			}
		}
	}
}